#include "CallWidget.h"
#include "ui_CallWidget.h"
#include <QDebug>
#include <smartphone/Smartphone.h>
CallWidget::CallWidget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::CallWidget)
{
    ui->setupUi(this);
    this->setWindowFlags( Qt::Tool | Qt::WindowStaysOnTopHint | Qt::X11BypassWindowManagerHint); //隐藏菜单栏
    this->setAutoFillBackground(true);
    mBackPixmap = QPixmap(":/images/bk/bk_callwidget.png");
    setBackgroundImage(mBackPixmap);
    isRecording = false;
}

CallWidget::~CallWidget()
{

    delete ui;
}
void CallWidget::closeEvent(QCloseEvent *event)
{
    Smartphone::getInstance()->terminate(Smartphone::getInstance()->getCurrentCallid());
}

QWidget* CallWidget::getDisplay()
{
    return ui->wDisp;
}
QWidget* CallWidget::getDisplayPreview()
{

    return ui->wDispPreview;
}

void CallWidget::resizeEvent(QResizeEvent *event)
{
    setBackgroundImage(mBackPixmap);
}
void CallWidget::setBackgroundImage(QPixmap &pixmap)
{
    if(pixmap.isNull())
    {
        qDebug()<<"illege argument"<<endl;

        return;
    }
    QPalette palette = this->palette();
    palette.setBrush(this->backgroundRole(),QBrush(pixmap.scaled(this->size(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation)));
    this->setPalette(palette);
}

void CallWidget::on_btnHungup_clicked()
{
    Smartphone::getInstance()->terminate(Smartphone::getInstance()->getCurrentCallid());


}

void CallWidget::on_btnOpen_clicked()
{
    Smartphone::getInstance()->sendInfo("squirrelunlock", Smartphone::getInstance()->getCurrentCallid());
}

void CallWidget::on_btnRecord_clicked()
{
    if(isRecording == false)
    {
        isRecording = true;
        Smartphone::getInstance()->startRecording();
        QPalette pal = ui->btnRecord->palette();
        pal.setColor(QPalette::ButtonText, Qt::red);    //设置按钮上的字体颜色，理论上可以，实际上就是可以
        ui->btnRecord->setPalette(pal);

    }
    else
    {
        isRecording = false;
        Smartphone::getInstance()->stopRecording();
        QPalette pal = ui->btnRecord->palette();
        pal.setColor(QPalette::ButtonText, Qt::black);    //设置按钮上的字体颜色，理论上可以，实际上就是可以
        ui->btnRecord->setPalette(pal);
    }
}

void CallWidget::on_btnTakePhoto_clicked()
{
    Smartphone::getInstance()->takePreviewSnapshot(Smartphone::getInstance()->getCurrentCallid(), "./picture.jpg");
}
